package com.cntaiping.workutil.prometheus;

import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Component
public class MetricsFactory {
    private static List<BatchVisConRes> metricsList;

    public MetricsFactory(){
        metricsList = new ArrayList<>();
    }

    public List<BatchVisConRes> getMetricsList(){
        if(metricsList == null){
            metricsList = new ArrayList<>();
        }
        return metricsList;
    }

    public void addMetrics(BatchVisConRes batchVisConRes){
        metricsList.add(batchVisConRes);
    }

    public void clearMetricsList(){
        metricsList.clear();
    }

    public void remove(BatchVisConRes batchVisConRes){
        List<BatchVisConRes> batchVisConResList =  metricsList.stream().filter(item -> item.getApiName().equals(batchVisConRes.getApiName())).collect(Collectors.toList());
        if(batchVisConResList.size()>0){
            metricsList.remove(batchVisConResList.get(0));
        }

    }
}
